package com.liao.ticket.controller;

import com.liao.ticket.common.exception.ErrorCode;
import com.liao.ticket.dao.pojo.User;
import com.liao.ticket.service.LoginService;
import com.liao.ticket.vo.Result;
import com.liao.ticket.vo.UserVo;
import com.liao.ticket.vo.params.LoginParams;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 接口测试成功
 * 1.0.0
 */
@RestController
@RequestMapping("login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping
    public Result login(@RequestBody LoginParams loginParams) {
        return loginService.login(loginParams);
    }

    @GetMapping
    public Result checkToken(@RequestHeader String token) {
        User user = loginService.checkToken(token);
        if (user == null) {
            return Result.fail(ErrorCode.USER_NO_EXIT);
        }
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(user,userVo);
        return Result.success(userVo);
    }

}
